<?php

use yii\grid\GridView;
use common\helpers\Html;
use common\helpers\ImageHelper;

$this->title = '书籍管理';
$this->params['breadcrumbs'][] = $this->title;

/* @var $this \yii\web\View */
/* @var $dataProvider \yii\data\ActiveDataProvider */
/* @var $searchModel \common\models\base\SearchModel */

?>
<div class="row">
    <div class="col-xs-12">
    <div class="box">
    <div class="box-header">
        <h3 class="box-title"><?= $this->title; ?></h3>
        <div class="box-tools">
            <?= Html::create(['edit']) ?>
        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body table-responsive">
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            //重新定义分页样式
            'tableOptions' => ['class' => 'table table-hover'],
            'columns' => [
                [
                    'class' => 'yii\grid\SerialColumn',
                    'visible' => false, // 不显示#
                ],
                'id',
                ['label' =>'分类名称',
                    'attribute' => 'booksCate.title',
                    'filter' => true, //显示搜索框

                ],
                [
                    'attribute' => 'image',
                    'value' => function ($model) {
                        return Html::img(ImageHelper::defaultHeaderPortrait(Html::encode($model->image)),
                            [
                                'class' => 'rf-img-md img-bordered-sm',
                            ]);
                    },
                    'filter' => false,
                    'format' => 'raw',
                ],
                'name',
                ['label' =>'简介',
                    'attribute' => 'desc',
                    'filter' => true, //显示搜索框
                    'value' => function($model){
                        return $model->desc;
                    }
                ],
                [
                    'attribute' => 'file',
                    'value' => function ($model) {
                        return Html::img(ImageHelper::defaultHeaderPortrait(Html::encode($model->file)),
                            [
                                'class' => 'rf-img-md img-bordered-sm',
                            ]);
                    },
                    'filter' => false,
                    'format' => 'raw',
                ],
                'author',
                'heat_degree',
                'read_num',
                'book_status',
                'words',
                'collect',
                'advert',
                [
                    'attribute' => 'sort',
                    'format' => 'raw',
                    'headerOptions' => ['class' => 'col-md-1'],
                    'value' => function ($model, $key, $index, $column){
                        return  Html::sort($model->sort);
                    }
                ],
                [
                    'label' => '创建时间',
                    'attribute' => 'created_at',
                    'filter' => false, //不显示搜索框
                    'format' => ['date', 'php:Y-m-d H:i:s'],
                ],
                [
                    'label' => '修改时间',
                    'attribute' => 'updated_at',
                    'filter' => false, //不显示搜索框
                    'format' => ['date', 'php:Y-m-d H:i:s'],
                ],
                [
                    'header' => "操作",
                    'class' => 'yii\grid\ActionColumn',
                    'template' => '{edit} {status} {delete}',
                    'buttons' => [
                        'edit' => function ($url, $model, $key) {
                            return Html::edit(['edit', 'id' => $model->id]);
                        },
                        'status' => function ($url, $model, $key) {
                            return Html::status($model->status);
                        },
                        'delete' => function ($url, $model, $key) {
                            return Html::delete(['delete', 'id' => $model->id]);
                        },
                    ],
                ],
            ],
        ]); ?>
        <!-- /.box-body -->
    </div>
        <!-- /.box -->
    </div>
    </div>
</div>